package com.example.kotlin.jetpack_compose_by_tutorials

import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.window.DialogProperties
import com.example.myapplication.R

/**
 *Create by Fanketly on 2022/9/15
 *Gitee:https://gitee.com/fanketly
 *desc:
 */
@Composable
fun MyAlertDialog() {
    val shouldShowDialog = remember { mutableStateOf(true) }
    if (shouldShowDialog.value) { // 2
        AlertDialog( // 3
            onDismissRequest = { // 4
                shouldShowDialog.value = false
            },
            // 5
            title = { Text(text = "title") },
            text = { Text(text = "text") },
            confirmButton = { // 6
                Button(
                    colors = ButtonDefaults.buttonColors(
                        backgroundColor =
                        colorResource(id = R.color.teal_200)
                    ),
                    onClick = {
                        shouldShowDialog.value = false
                    }
                ) {
                    Text(text = "确认", color = Color.White)
                }
            },
            shape = MaterialTheme.shapes.medium,
            backgroundColor = MaterialTheme.colors.surface,
            properties = DialogProperties()
        )
    }
}

